package com.jufanshare.myblog.conf;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.Executor;

/**
 * 作用：配置定时任务异步执行
 * 作者：Tiddler
 * 时间：2019/2/10 12：58
 * 类名： AsyncConfig
 **/
@Configuration
public class AsyncConfig {
    @Value("${conf.async.corePoolSize}")
    private int corePoolSize;
    @Value("${conf.async.maxPoolSize}")
    private int maxPoolSize;
    @Value("${conf.async.queueCapacity}")
    private int queueCapacity;
    @Bean
    public Executor taskExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(corePoolSize);
        executor.setMaxPoolSize(maxPoolSize);
        executor.setQueueCapacity(queueCapacity);
        executor.initialize();
        return executor;
    }
}
